package springAop.jdkProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by mHandler on 2018/6/26 0026.
 * Description:
 */
public class ProxyUtil {

    public static UserDao getProxy(UserDao dao){

        UserDao proxy=(UserDao)Proxy.newProxyInstance(dao.getClass().getClassLoader(),
                dao.getClass().getInterfaces(), new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        if ("update".equals(method.getName())){
                            System.out.println("增强update");
                        }else if ("save".equals(method.getName())){
                            System.out.println("增强save");
                        }
                        return method.invoke(dao,args);
                    }
                });

        return proxy;
    }
}
